package com.customer.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class JedisUtil {
    private static final JedisPool jedisPool;

    static {
        InputStream resource = JedisUtil.class.getClassLoader().getResourceAsStream("redis.properties");

        Properties properties = new Properties();

        try {
            properties.load(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }

        JedisPoolConfig poolConfig = new JedisPoolConfig();

        poolConfig.setMaxTotal(Integer.parseInt(properties.getProperty("maxTotal")));
        poolConfig.setMaxIdle(Integer.parseInt(properties.getProperty("maxIdle")));

        jedisPool = new JedisPool(poolConfig, properties.getProperty("host"), Integer.parseInt(properties.getProperty("port")));
    }


    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}

